﻿using TribesPSO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TribesPSOTest
{


    /// <summary>
    ///This is a test class for ParticleTest and is intended
    ///to contain all ParticleTest Unit Tests
    ///</summary>
    [TestClass()]
    public class IndependantGaussianParticleTest : ParticleTest
    {

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        protected override Particle CreateParticle()
        {
            return new IndependentGaussianParticle(new Rosenbrock(), EuclidianVector.Origin(2));
        }

        protected override Particle CreateParticle(EuclidianVector position, IObjectiveFunction function)
        {
            return new IndependentGaussianParticle(function, position);
        }

        /// <summary>
        ///A test for CalculateNewPosition
        ///</summary>
        [TestMethod()]
        public void CalculateNewPositionTest()
        {

            IObjectiveFunction function = new Rosenbrock();
            EuclidianVector initialPosition = new EuclidianVector(0, 10);
            EuclidianVector bestPosition = new EuclidianVector(1, 1);

            Particle_Accessor target = CreateParticle_Accessor(initialPosition, new Rosenbrock());
            Solution idealSolution = new Solution(bestPosition, function);

            EuclidianVector newPosition = target.CalculateNewPosition(idealSolution);

            //Check that we moved closer to the ideal solution
            Assert.IsTrue((newPosition - bestPosition).Length < (initialPosition - bestPosition).Length);
        }
    }
}
